package com.example.droideep.fragment.animstudy;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.v4.app.Fragment;
import android.view.animation.LinearInterpolator;

import com.example.droideep.R;
import com.example.droideep.common.activities.SimpleFragmentBase;

import butterknife.InjectView;
import butterknife.OnClick;
import droideep.library.widget.FloatingActionButton;

/**
 * @author bri
 * @date 15-5-15.
 */
public class AnimatorSetFragment extends SimpleFragmentBase {

    public static final String TAG = AnimatorSetFragment.class.getSimpleName();
    @InjectView(R.id.floating_action_button)
    FloatingActionButton mFab;

    @Override
    protected int getContentResId() {
        return R.layout.fragment_animator_set;
    }

    public static Fragment newInstance() {
        return new AnimatorSetFragment();
    }

    @OnClick(R.id.togetherRun)
    public void togetherRun() {
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(mFab, "scaleX", 1.0f, 2f);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(mFab, "scaleY", 1.0f, 2.0f);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(2000L);
        animatorSet.setInterpolator(new LinearInterpolator());
        // 两个动画同时执行
        animatorSet.playTogether(animator1, animator2);
        animatorSet.start();
    }

    @OnClick(R.id.playWithAfter)
    public void playWithAfter() {
        float cx = mFab.getX();

        ObjectAnimator anim1 = ObjectAnimator.ofFloat(mFab, "scaleX",
                1.0f, 2f);
        ObjectAnimator anim2 = ObjectAnimator.ofFloat(mFab, "scaleY",
                1.0f, 2f);
        ObjectAnimator anim3 = ObjectAnimator.ofFloat(mFab,
                "x", cx, 0f);
        ObjectAnimator anim4 = ObjectAnimator.ofFloat(mFab,
                "x", cx);

        /**
         * anim1，anim2,anim3同时执行 
         * anim4接着执行 
         */
        AnimatorSet animSet = new AnimatorSet();
        animSet.play(anim1).with(anim2);
        animSet.play(anim2).with(anim3);
        animSet.play(anim4).after(anim3);
        animSet.setDuration(1000);
        animSet.start();
    }
}
